#!/usr/bin/env python3
"""
Launcher script for visualizing interactions between categories.

This is a thin wrapper that imports and calls the visualization function from
src.connecting_people.viz.interactions.
"""
import argparse
import sys
from pathlib import Path

# Add the src directory to the Python path to enable imports
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))

from connecting_people.viz.interactions import visualise_interactions
import pandas as pd


def main():
    """Parse command-line arguments and visualize interactions."""
    parser = argparse.ArgumentParser(
        description="Visualize inter-century interactions between two categories."
    )
    parser.add_argument(
        "--input-file",
        type=str,
        required=True,
        help="Path to the input parquet or CSV file with interaction data"
    )
    parser.add_argument(
        "--category1",
        type=str,
        required=True,
        help="Source category label (e.g., 'Science')"
    )
    parser.add_argument(
        "--category2",
        type=str,
        required=True,
        help="Target category label (e.g., 'Politics')"
    )
    parser.add_argument(
        "--direction",
        type=str,
        choices=["row", "col"],
        default="row",
        help="Normalization direction: 'row' or 'col'"
    )
    parser.add_argument(
        "--no-visualize",
        action="store_true",
        help="Don't display the plot"
    )
    parser.add_argument(
        "--save",
        action="store_true",
        help="Save the figure to disk"
    )

    args = parser.parse_args()

    # Load the data
    input_path = Path(args.input_file)
    if input_path.suffix == ".parquet":
        df = pd.read_parquet(input_path)
    elif input_path.suffix == ".csv":
        df = pd.read_csv(input_path)
    else:
        raise ValueError(f"Unsupported file format: {input_path.suffix}")

    # Call the visualization function
    visualise_interactions(
        df=df,
        category1_label=args.category1,
        category2_label=args.category2,
        direction=args.direction,
        visualize=not args.no_visualize,
        save_figure=args.save,
    )

    print(f"Interaction visualization completed: {args.category1} → {args.category2}")


if __name__ == "__main__":
    main()
